using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
using Developex.GenerateClassOnShema.Classes;

namespace Developex.GenerateClassOnShema
{
	public partial class MainForm : Form
	{
		public MainForm()
		{
			InitializeComponent();
		}

		private void btnGenerateByIniFile_Click(object sender, EventArgs e)
		{
			if (!CheckEmpty(txtOutputFolder.Text, "Output folder") ||
				 !CheckEmpty(txtIniFileName.Text, "Ini file name") ||
				 !CheckEmpty(txtNamespace.Text, "Namespace") ||
				 !CheckEmpty(txtConnectionString.Text, "Connection string"))
			{
				return;
			}
			try
			{
				string indent = "";
				if (rbtIndentSize_tabs.Checked)
					indent = "\t";
				else if (rbtIndentSize_1.Checked)
					indent = " ";
				else if (rbtIndentSize_2.Checked)
					indent = "  ";
				else if (rbtIndentSize_3.Checked)
					indent = "   ";
				else if (rbtIndentSize_4.Checked)
					indent = "    ";

				// TODO: add checkbox for CE
				Generator.GenerateClassesForDatabase(txtIniFileName.Text, txtOutputFolder.Text, txtConnectionString.Text, txtNamespace.Text, indent, chkCE.Checked, chkAddEncoded.Checked, chkSql2000.Checked);
				MessageBox.Show("Generated!");
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private bool CheckEmpty(string text, string message)
		{
			if (string.IsNullOrEmpty(text))
			{
				MessageBox.Show(message + " should not be empty");
				return false;
			}
			return true;
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void MainForm_Load(object sender, EventArgs e)
		{

		}

	}
}